package com.rainbowred.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.rainbowred.common.enums.ErrorCode;
import com.rainbowred.common.execption.BusinessException;
import com.rainbowred.common.util.StringUtil;
import com.rainbowred.system.domain.EdpDeveloper;
import com.rainbowred.system.service.EdpDeveloperService;
import com.rainbowred.system.mapper.EdpDeveloperMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* @author pengweibiao
* @description 针对表【edp_developer(开发者配置表)】的数据库操作Service实现
* @createDate 2023-10-29 16:37:20
*/
@Service
public class EdpDeveloperServiceImpl extends ServiceImpl<EdpDeveloperMapper, EdpDeveloper>
implements EdpDeveloperService{

    @Autowired
    private EdpDeveloperMapper mapper;

    @Override
    public Boolean verifyRepeat(String name) {
        // 参数校验
        if (StringUtil.isEmpty(name)) {
            return false;
        }
        // 构建查询参数
        QueryWrapper<EdpDeveloper> qw = new QueryWrapper<>();
        qw.eq("name", name).eq("disable", 0).eq("del_flag", 0);

        // 查询数量，返回是否唯一
        if (this.count(qw) > 0) {
            return false;
        }else {
            return true;
        }
    }

    @Override
    public EdpDeveloper addOne(EdpDeveloper pojo) {
        if (verifyRepeat(pojo.getName())) {
            pojo.initPojo();
            pojo.initDevId();
            // 插入数据
            this.save(pojo);
            return pojo;
        }else {
            throw new BusinessException(ErrorCode.E1001, "填入名称重复");
        }
    }
}
